
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title id="divTitle"> 添加书籍 </title>
    <link rel="stylesheet" type="text/css" href="/css/style.css" />

    <style type="text/css">
        *, body {
            margin: 0px;
            font-family: '微软雅黑';
        }
    </style>
    <script src="~/js/jquery-1.10.2.min.js"></script>
    <script src="~/js/jquery.form.js"></script>
    <script src="~/js/generic.js"></script>

    <script type="text/javascript" src="~/js/EasyUI/jquery.ui.widget.js"></script>
    <script type="text/javascript" src="~/js/EasyUI/jquery.iframe-transport.js"></script>
    <script type="text/javascript" src="~/js/EasyUI/jquery.fileupload.js"></script>
    <script type="text/javascript" src="~/js/EasyUI/jquery.fileupload-process.js"></script>
    <script type="text/javascript" src="~/js/EasyUI/jquery.fileupload-validate.js"></script>
    <script type="text/javascript" src="~/js/EasyUI/jquery.fileupload-ui.js"></script>
    <script type="text/javascript">
    </script>
</head>

<body>

@Html.Partial("top")
<form id="filePost" method="post" enctype="multipart/form-data" onsubmit="return false;">
    <table class="maintable">
        <tr>
            @Html.Partial("Menu")
            <td class="rightmaintd" valign="top">
                <div style="width:920px;margin:10px auto;"> <a href="/Book/list">&lt;  返回</a> </div>
                <table class="logintable" cellpadding="8" style="margin-top:20px;">
                    <tr>
                        <td width="100">书名</td>
                        <td><input type="text" id="name" class="logininput"></td>
                    </tr>
                    <tr>
                        <td>作者</td>
                        <td><input type="text" id="author" class="logininput"></td>
                    </tr>
                    <tr>
                        <td>出版社</td>
                        <td><input type="text" id="publisher" class="logininput"></td>
                    </tr>
                    <tr>
                        <td>版次</td>
                        <td><input type="text" id="edition" class="logininput"></td>
                    </tr>
                    <tr>
                        <td>出版时间</td>
                        <td><input type="text" id="editionTime" class="logininput"></td>
                    </tr>
                    <tr>
                        <td>ISBN</td>
                        <td><input type="text" id="isbn" class="logininput"></td>
                    </tr>
                    <tr>
                        <td>医家</td>
                        <td><input type="text" id="medicalDoctor" class="logininput"></td>
                    </tr>
                    <tr>
                        <td valign="top">封面</td>
                        <td>
                            <img src="/images/userhead.png" id="img4" alt="" class="userheadpic"> <br />
                            <div class="fileUpload">
                                <span id="spSmallImage4">上传封面</span>
                                <input type="file" id="smallfile4" name="smallfile4" class="upload" />
                                <input type="hidden" id="hidSmallPic4" value="" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">版权页</td>
                        <td>
                            <img src="/images/userhead.png" id="img5" alt="" class="userheadpic"> <br />
                            <div class="fileUpload">
                                <span id="spSmallImage5">上传版权页</span>
                                <input type="file" id="smallfile5" name="smallfile5" class="upload" />
                                <input type="hidden" id="hidSmallPic5" value="" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><input type="button" value="保&nbsp;&nbsp;存" class="denglubtn" onclick="saveInfo();">  </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</form>
@Html.Partial("bottom")

</body>
</html>
<script type="text/javascript">
    var _app_guid = '@ViewBag.Guid';
    var _app_edit = '@ViewBag.EditState';
    var submit = true;
    $(document).ready(function() {
        if (_app_edit == "edit") {
            util.getJSON("/Book/GetBook", { "id": _app_guid }, function(json) {
                if (json.status == 0) {
                    $("#name").val(json.book.name);
                    $("#author").val(json.book.author);
                    $("#publisher").val(json.book.publisher);
                    $("#edition").val(json.book.edition);
                    $("#editionTime").val(json.book.editionTime);
                    $("#isbn").val(json.book.isbn);
                    $("#medicalDoctor").val(json.book.medicalDoctor);
                    $("#hidSmallPic4").val(json.book.bookCoverName);
                    $("#img4").attr("src", "/files/book/cover/" + json.book.bookCoverName);
                    $("#hidSmallPic5").val(json.book.copyRightMapName);
                    $("#img5").attr("src", "/files/book/copyRight/" + json.book.copyRightMapName);
                }
            });
            $("#divTitle").html("更新书籍");

        } else {
            $("#divTitle").html("创建书籍");
        }
    });

    //保存
    function saveInfo() {
        if ($("#name").val() == "") {
            alert("请输入书名");
            $("#name").focus();
            return;
        }
        var book = {
            "name": $("#name").val(),
            "author": $("#author").val(),
            "publisher": $("#publisher").val(),
            "edition": $("#edition").val(),
            "email": $("#email").val(),
            "editionTime": $("#editionTime").val(),
            "isbn": $("#isbn").val(),
            "medicalDoctor":$("#medicalDoctor").val(),
            "bookCoverName": $("#hidSmallPic4").val(),
            "copyRightMapName": $("#hidSmallPic5").val()
        };
        var url = _app_edit != "edit" ? "/Book/Create" : "/Book/Update";
        if (_app_edit == "edit") {
            book.id = _app_guid;
        }
        util.postJson(url,
            {
                "book": book
            }, function (json) {
                if (json.status == 0) {
                    alert(json.msg);
                    location.href = "/Book/List";
                } else {
                    alert(json.msg);
                }
            });
    }
    $(function () {
        $("#smallfile4").change(function () {
            $("#spSmallImage4").html("正在上传");
            $("#filePost").ajaxSubmit({
                url: "/Files/UploadBookCover",
                success: function (data) {
                    var json = JSON.parse(data);
                    if (json.status == 0) {
                        $("#hidSmallPic4").val(json.msg);
                        $("#img4").attr("src", "/files/book/cover/" + json.msg);
                    } else {
                        alert(json.msg);
                    }
                    $("#spSmallImage4").html("上传图片");
                }
            });
        });
    });
    //上传版权页
    $(function () {
        $("#smallfile5").change(function () {
            $("#spSmallImage5").html("正在上传");
            $("#filePost").ajaxSubmit({
                url: "/Files/UploadBookCopy",
                success: function (data) {
                    var json = JSON.parse(data);
                    if (json.status == 0) {
                        $("#hidSmallPic5").val(json.msg);
                        $("#img5").attr("src", "/files/book/copyRight/" + json.msg);
                    } else {
                        alert(json.msg);
                    }
                    $("#spSmallImage5").html("上传图片");
                }
            });
        });
    });
</script>